package be.bonamis.umpire.domain.quiz;

import java.util.Date;
import java.util.List;

import javax.persistence.ElementCollection;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.Id;
import javax.persistence.IdClass;

import org.apache.openjpa.persistence.Externalizer;
import org.apache.openjpa.persistence.Factory;
import org.apache.openjpa.persistence.Persistent;
import org.joda.time.DateTime;

@Entity
@IdClass(PersonQuizId.class)
public class PersonQuiz {
	
	@Id
	private long personId;
	@Id
	private long quizId;
	@Persistent
	@Externalizer("toDate")
	@Factory("PersonQuiz.dateTimeToJoda")
	private DateTime responseDay;
	@ElementCollection(fetch=FetchType.EAGER)
	private List<Boolean> responses;
	
	public PersonQuiz() {	
	}

	public long getPersonId() {
		return personId;
	}

	public void setPersonId(long personId) {
		this.personId = personId;
	}

	public long getQuizId() {
		return quizId;
	}

	public void setQuizId(long quizId) {
		this.quizId = quizId;
	}

	public DateTime getResponseDay() {
		return responseDay;
	}

	public void setResponseDay(DateTime responseDay) {
		this.responseDay = responseDay;
	}

	public List<Boolean> getResponses() {
		return responses;
	}

	public void setResponses(List<Boolean> responses) {
		this.responses = responses;
	}

	public static DateTime dateTimeToJoda(Date dateTime) {
		return new DateTime(dateTime) ;       
    }
}
